import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.regex.*;

public class LombokRemover {
    private static final String BASE_PATH = "d:\\projects\\zhixin\\minimalist-saas\\minimalist-common\\src\\main\\java\\com\\minimalist\\common\\entity";
    
    public static void main(String[] args) throws IOException {
        processDirectory(Paths.get(BASE_PATH));
    }
    
    private static void processDirectory(Path dir) throws IOException {
        Files.walk(dir)
            .filter(path -> path.toString().endsWith(".java"))
            .forEach(LombokRemover::processFile);
    }
    
    private static void processFile(Path filePath) {
        try {
            String content = Files.readString(filePath);
            String originalContent = content;
            
            // 检查是否包含lombok注解
            if (!content.contains("@Data") && !content.contains("@Getter") && 
                !content.contains("@Setter") && !content.contains("@AllArgsConstructor") &&
                !content.contains("@NoArgsConstructor") && !content.contains("@Builder") &&
                !content.contains("@ToString") && !content.contains("@EqualsAndHashCode")) {
                return;
            }
            
            System.out.println("Processing: " + filePath);
            
            // 移除lombok导入
            content = content.replaceAll("import lombok\\..*?;\\n", "");
            
            // 移除lombok注解
            content = content.replaceAll("@Data\\n", "");
            content = content.replaceAll("@Getter\\n", "");
            content = content.replaceAll("@Setter\\n", "");
            content = content.replaceAll("@AllArgsConstructor\\n", "");
            content = content.replaceAll("@NoArgsConstructor\\n", "");
            content = content.replaceAll("@Builder\\n", "");
            content = content.replaceAll("@ToString\\n", "");
            content = content.replaceAll("@EqualsAndHashCode.*?\\n", "");
            
            // 添加Objects导入（如果需要）
            if (!content.contains("import java.util.Objects;")) {
                content = content.replaceFirst("(import.*?;\\n)", "$1import java.util.Objects;\\n");
            }
            
            // 如果内容有变化，写回文件
            if (!content.equals(originalContent)) {
                Files.writeString(filePath, content);
                System.out.println("Updated: " + filePath);
            }
            
        } catch (IOException e) {
            System.err.println("Error processing " + filePath + ": " + e.getMessage());
        }
    }
}